﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_EditPassword : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            tbUserName.Text = _User.Name;
        }

        tbOldUserPassword2.Attributes.Add("value", tbOldUserPassword2.Text);
        tbNewUserPassword.Attributes.Add("value", tbNewUserPassword.Text);
        tbNewUserPassword_2.Attributes.Add("value", tbNewUserPassword_2.Text);
        tbNewUserPassword2.Attributes.Add("value", tbNewUserPassword2.Text);
        tbNewUserPassword2_2.Attributes.Add("value", tbNewUserPassword2_2.Text);
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/EditPassword.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (PublicFunction.EncryptPassword(tbOldUserPassword2.Text.Trim()) != _User.Password2)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "旧二级密码错误！");
            return;
        }

        if (tbNewUserPassword.Text.Trim() == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "新一级密码不能为空！");
            return;
        }

        if (tbNewUserPassword.Text != tbNewUserPassword_2.Text)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "二次输入的新一级密码不一致！");
            return;
        }

        if (tbNewUserPassword2.Text.Trim() == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "新二级密码不能为空！");
            return;
        }

        if (tbNewUserPassword2.Text != tbNewUserPassword2_2.Text)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "二次输入的新二级密码不一致！");
            return;
        }

        string Return = "";
        _User.GetUserInfoByID(ref Return);

        User tu = new User();
        _User.Clone(tu);

        tu.Password = PublicFunction.EncryptPassword(tbNewUserPassword.Text.Trim());
        tu.Password2 = PublicFunction.EncryptPassword(tbNewUserPassword2.Text.Trim());

        Return = "";
        int Result = tu.EditByID(ref Return);

        if (Result == 0)
        {
            tu.Clone(_User);

            ShoveEL._Web.JavaScript.Alert(this.Page, "密码修改成功。请妥善保管好您的密码！");
        }
        else
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, Return);
        }
    }
}